package cn.lijigou.shopping.domain;

import org.json.JSONArray;
import org.json.JSONObject;

/**
 * @author 董永健 E-mail:dong_yong_jian@163.com
 * @version 创建时间：2012-1-6 上午11:45:05
 * 同服务器交换返回的结果类
 */
public class MResult {
	public int status = 0;			//请求状态
	public String info   ="";		//提示信息
	public String data   = "";		//数据内容
	public String errorCode   = "";  //异常编码
	public boolean page = true;
	
	public MResult(byte[] datas) {
		try {
			String jsonStr= new String(datas);
			JSONArray json =new JSONArray("["+jsonStr+"]");
			for(int i=0;i<json.length();i++){
				JSONObject item = json.getJSONObject(i);
				if(item.has("status")){status =(int) item.getInt("status");}
				if(item.has("info")){info =(String) item.getString("info");}
				if(item.has("data")){data =(String) item.getString("data");}
				if(item.has("errorCode")){errorCode =(String) item.getString("errorCode");}
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public MResult(String jsonStr) {
		try {
			JSONArray json =new JSONArray("["+jsonStr+"]");
			for(int i=0;i<json.length();i++){
				JSONObject item = json.getJSONObject(i);
				if(item.has("status")){status =(int) item.getInt("status");}
				if(item.has("info")){info =(String) item.getString("info");}
				if(item.has("data")){data =(String) item.getString("data");}
				if(item.has("errorCode")){errorCode =(String) item.getString("errorCode");}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public MResult() {
		super();
	}
	
	public  boolean isPage() {
		return page;
	}

	public void setPage(boolean page) {
		this.page = page;
	}

	public boolean isSuccess(){
		if(status==1){
			return true;
		}
		return false;
	}

	public String getErrorCode() {
		return errorCode;
	}

	public String getData() {
		return data;
	}

	public void setData(String data) {
		this.data = data;
	}

	public String getInfo() {
		return info;
	}

	public void setInfo(String info) {
		this.info = info;
	}
	
}
